<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AllBroadcastEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($msg)
    {
        $this->msg = $msg;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('chat-public');
    }

    /**
     * 事件的广播名称
     * 客户端
     * Echo.channel('channel-name')
         .listen('.{name}', (e) => {
        // 处理事件数据
        });
     * 如果不指定 事件名 就是包含命名空间的类名
     *
     * @return string
     */
    public function broadcastAs()
    {
        return 'hello';
    }

    // 自定义广播数据（可选）
    public function broadcastWith()
    {
        return [
            'status' => '200',
            'message' => 'ok',
        ];
    }
}
